Macromedia Flex Article

Learning Flex Basics (Part 3) : Working with Containers


Table of Contents

  1. Introduction
  2. Building the Containers
  3. Create the Application Object
  4. Create a Data Array
  5. Add a TabNavigator Container for Global Navigation
  6. Add an HBox and Panel Containers for Main Views
  7. Add a ViewStack, LinkBar, and Panel Containers for Secondary Views
  8. Add a Form Container
  9. Add a Tile Layout Container and Populate It Using a Repeater
  10. Create a Pseudo Bar Chart Using a Repeater and VBoxes
  11. Complete Code Listing for containers.mxml
  12. Where to Go from Here

Add a Form Container

The navigation of our simple application is now complete, and for the rest of the tutorial you focus on the use of layout containers. First, you create a Form container, which automatically arranges form controls and also provides some aids for handling the processing of form data (which you won't use here, but are straightforward and covered in the Flex documentation). You can use ordinary event handlers for form data also, as you do in this exercise.

The Form works with two nested container classes:

  • FormHeading: Creates one or more headings (this is optional - you can use Labels as well)
  • FormItem: Creates labels for a control or a group of controls

Inside the Form, you use a ComboBox, similar to an HTML select control. The ComboBox is covered in more detail in Learning Flex Basics (Part 1): Creating Your First Flex Application. The ComboBox items are generated from an array of simple values or objects; here, you use the array you created in the Script block earlier.

You also create a ControlBar container in this section. A ControlBar is an optional footer container for a Panel with a horizontal layout.

  1. Inside the Panel with the title "Form," add a Form container:

    <mx:Form>
    </mx:Form>
    
  2. Inside the Form, add a FormHeading with the label My Form:

    <mx:FormHeading label="My Form"/>
    
  3. After the FormHeading, add a FormItem container block with the label Pick a Number:

    <mx:FormItem label="Pick a Number">
    </mx:FormItem>
    
  4. Inside the FormItem, add a ComboBox with the id of myCombo and the dataProvider property bound to myArray:

    <mx:ComboBox id="myCombo" dataProvider="{myArray}"/>
    
  5. After the Form container, but still inside the Panel, add a ControlBar container:

    <mx:ControlBar>
    </mx:ControlBar>
  6. Inside the ControlBar container, add a Label whose text is the string "You chose: " joined to a binding to the selectedItem property of the ComboBox:

    <mx:Label text="You chose: {myCombo.selectedItem}"/>
    
  7. Save the file and browse it to see the form; select an different item in the ComboBox to see the Label in the ControlBar container change.